package com.kara.entity;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.appfuse.model.BaseObject;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenericGenerator;

@Entity
@Table(name = "student")
@NamedQueries({
		@NamedQuery(name = "findStuentByFirstName", query = "select s from Student s where s.firstName = :firstName"),
		@NamedQuery(name = "findStuentByLastName", query = "select s from Student s where s.lastName = :lastName") })
public class Student extends BaseObject {

	private Long id;
	private String firstName;
	private String lastName;
	private String email;
	private Date dateOfBirth;
	private String mobilePhone;
	
	@Id
	@SequenceGenerator(name = "EMP_SEQ_GEN", sequenceName = "emp_sequence")
	@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EMP_SEQ_GEN")
	
	public Long getId() {
		return id;
	}
	@Column(name="first_name", length=255, nullable=false)
	public String getFirstName() {
		return firstName;
	}
	@Column(name="last_name", length=255, nullable=false)
	public String getLastName() {
		return lastName;
	}

	@Column(name="email", length=300, nullable=false)
	public String getEmail() {
		return email;
	}
	@Column(name="mobile_phone", length=11)
	public String getMobilePhone() {
		return mobilePhone;
	}
	@Column(name="date_birth")
	@Temporal(TemporalType.TIME)
	public Date getDateOfBirth() {
		return dateOfBirth;
	}
	public void setId(Long id) {
		this.id = id;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public void setDateOfBirth(Date dateOfBirth) {
		this.dateOfBirth = dateOfBirth;
	}
	
	public void setMobilePhone(String mobilePhone) {
		this.mobilePhone = mobilePhone;
	}
	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.DEFAULT_STYLE)
				.append("id", id).append("firstName", firstName)
				.append("lastName", lastName)
				.append("dateOfBrith", dateOfBirth).append("email", email)
				.toString();
	}

	@Override
	public boolean equals(Object o) {
		if (!(o instanceof Student)) {
			return false;
		}
		if (o == this) {
			return true;
		}
		Student st = (Student) o;
		if (st.getId().equals(this.getId())) {
			return true;
		}
		return false;
	}

	@Override
	public int hashCode() {
		if (this != null) {
			return this.getId().hashCode();
		}
		return 0;
	}
}
